using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using DIS_DAL_WS.Models;
using DIS_DAL_WS.Helpers;

namespace DIS_DAL_WS.DTO
{
    [DataContract]
	public class RoleDTO
	{
        [DataMember]
		public int ID { get; set; }
        [DataMember]
		public string Name { get; set; }
        [DataMember]
        public List<EmployeeDTO> Employees { get; set; }
        [DataMember]
        public List<RoleFunctionsDTO> RoleFunctions { get; set; }

        public static RoleDTO Translate(Role Entity)
        {
            if (Entity != null)
            {
                var dto = new RoleDTO
                {
                    ID = Entity.ID,
                    Name = Entity.Name,
                    Employees = new List<EmployeeDTO>(),
                    RoleFunctions = new List<RoleFunctionsDTO>()
                };
                if (Entity.Employee != null)
                {
                    foreach (var item in Entity.Employee)
                    {
                        dto.Employees.Add(EmployeeDTO.Translate(item));
                    }
                }
                if (Entity.RoleFunctions != null)
                {
                    foreach (var item in Entity.RoleFunctions)
                    {
                        dto.RoleFunctions.Add(RoleFunctionsDTO.Translate(item));
                    }
                }
                return dto;
            }
            return null;
        }

        public static RoleDTO TranslateBase(Role Entity)
        {
            if (Entity != null)
            {
                var dto = new RoleDTO
                {
                    ID = Entity.ID,
                    Name = Entity.Name
                };
                //GlobalVariables.Logger.Info("Entity.ID: " + Entity.ID);
                //GlobalVariables.Logger.Info("Entity.Name: " + Entity.Name);
                return dto;
            }
            return null;
        }

        public static Role Reverse(RoleDTO obj)
        {
            var entity = new Role
            {
                ID = obj.ID,
                Name = obj.Name
            };
            return entity;
        }

        public void UpdateEntity(ref Role entity)
        {
            entity.Name = Name;
        }
	}
}